package com.ThreadState;

public class ThreadStop implements Runnable{

    private boolean fg = true;

    @Override
    public void run() {
        int i = 0;
        while (fg){
            System.out.println("run->"+i++);
        }
    }
    public void stop(){
        this.fg = false;
    }
    public static void main(String[] args) {
        ThreadStop Ts = new ThreadStop();


        new Thread(Ts).start();
        /*
        * 主线程跑到950时 停止Ts线程
        * 950之前 2个线程同时在跑 之后只有主线程在跑
        * */
        for (int i = 0; i < 1000; i++) {
            if(i == 950){
                Ts.stop();//停止线程
                System.out.println("线程停止===================================");
            }
            System.out.println("main方法"+i);
        }
    }
}
